package com.xgry.bpm.config.datasouce.oldsource;

import com.alibaba.druid.pool.DruidDataSource;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import javax.sql.DataSource;

@Repository
public class MSFactory {

    @Autowired
    private JdbcTemplate jdbcTemplate;

    public JdbcTemplate getJdbcTemplate(){
        return jdbcTemplate;
    }

    /**
     * 原bpm项目MSFactory读取库所用，现在切换为返回yml文件所配置数据库链接（master）
     * @return
     * @throws Exception
     */
    @Deprecated
    public JdbcTemplate getJdbcTemplate_old()throws Exception{

        if(jdbcTemplate==null){
            DruidDataSource ds = new DruidDataSource();
            ds.setUrl("jdbc:sqlserver://169.254.240.99:1433;DatabaseName=BPM2020-MyTest");
            ds.setUsername("sa");
            ds.setPassword("ufida123_");
            ds.setDriverClassName("com.microsoft.sqlserver.jdbc.SQLServerDriver");
            ds.init();
            DataSource createDataSource = (DataSource) ds;
            jdbcTemplate=new JdbcTemplate();
            jdbcTemplate.setDataSource(createDataSource);

        }else {
            return jdbcTemplate;
        }
        return jdbcTemplate;
    }
}
